﻿using DemountCIM.Framework;
using DemountCIM.Framework.DataBase;
using DemountCIM.Framework.DataBase.Table;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace DemountCIM.ViewModels
{
    public class UserWindowModel
    {
        public UserWindowModel()
        {

        }

        public UserWindowModel(int id, int userId, string name, string pwd, UserLevel level)
        {
            UserId = userId;
            Id = id;
            UserName = name;
            PassWord = pwd;
            Level = level;
        }

        public int Id { get; set; }

        public int UserId { get; set; }

        public string UserName { get; set; }

        public string PassWord { get; set; }

        public UserLevel Level { get; set; }
    }

    public class UserManagerViewModel : BindableBase
    {
        public List<UserWindowModel> TotalContactList;

        public UserManagerViewModel()
        {
            TotalContactList = new List<UserWindowModel>();
            Update();
        }

        public void Update()
        {
            TotalContactList.Clear();

            var temp = DataBaseContainer.GetInstance().GetUserRepository().AsQueryable().ToPageList(0, 50);
            for (int i = 0; i < temp.Count; i++)
            {
                TotalContactList.Add(new UserWindowModel(i + 1, temp[i].Id, temp[i].Name, temp[i].Pwd, temp[i].Level));
            }
            ContactList = new ObservableCollection<UserWindowModel>(TotalContactList);
            var level = Enum.GetValues(typeof(UserLevel)).Cast<UserLevel>().Select(a => a.ToString()).ToList();
            level.RemoveAt(level.Count - 1);
            _userLevel = new ObservableCollection<string>(level);
        }


        private ObservableCollection<UserWindowModel> contactList;
        private ObservableCollection<string> _userLevel;

        /// <summary>
        /// 联系人列表
        /// </summary>
        public ObservableCollection<UserWindowModel> ContactList
        {
            get { return contactList; }
            set
            {
                SetProperty(ref contactList, value);
            }
        }

        public ObservableCollection<string> UserLevel
        {
            get { return _userLevel; }
            set { SetProperty(ref _userLevel, value); }
        }


    }
}
